/**
 * Copyright (C) 2015-2018 IQIYI
 * All rights reserved.
 *
 * Author     : 王海斌
 * E-mail     : wanghaibin@qiyi.com
 * Version    :
 * Date       : Fri 31 Aug 2018 03:23:53 PM CST
 * Destription: 测试map嵌套相关用法
 *
 */

#include <iostream>
#include <map>

using namespace std;

void test_upper_bound()
{
    map<int, int> segs_;
    segs_[0] = 1;
    map<int, int>::iterator it = segs_.upper_bound(0);
    if(it!=segs_.end()) {
        cout << "find upper bound" << endl;
        segs_.erase(it, segs_.end());
    } else {
        cout << "not find upper" << endl;
    }
}

// 测试map的默认排序begin最小, 依次到最大
void test_map_sort() {
    map<int, int> segs_;
    for(int i=0; i<100; i++) {
        segs_[i] = i;
    }
    map<int, int>::iterator it = segs_.begin();
    for(; it!= segs_.end(); ++it) {
        cout << it->first << endl;
    }
}

int main(int , char **)
{
    test_map_sort();
    return 0;
    test_upper_bound();
    map<int, map<int, int> > m1;
    for(int i=0; i<10; i++) {
        map<int, int> m2;
        m2.insert(make_pair(i,i));
        m2.insert(make_pair(i+10,i));
        m1.insert(make_pair(i, m2));
    }

    map<int, map<int, int> >::iterator it = m1.begin();
    cout << "m1.size=" << m1.size() << endl;
    for(; it != m1.end(); ++it) {
        map<int, int>::iterator it2 = it->second.begin();
        it->second.erase(it2);
        cout << it->first << " value size=" << it->second.size() << endl;
    }

    it = m1.begin();
    for(; it != m1.end(); ++it) {
        map<int, int>::iterator it2 = it->second.begin();
        it->second.erase(it2);
        cout << it->first << " 2value size=" << it->second.size() << endl;
    }
    return 0;
}
